﻿using Microsoft.Extensions.DependencyInjection;
using System;

namespace NetMicro.MongoProvider
{
    /// <summary>
    /// ServiceCollection扩展
    /// </summary>
    public static class ServiceCollectionExtensions
    {
        /// <summary>
        /// AddMongoDB
        /// </summary>
        /// <param name="services"></param>
        /// <param name="configuration"></param>
        public static IServiceCollection AddMongoDB<TContext>(this IServiceCollection services, Action<MongoDBConnectionConfig> configuration)
            where TContext : MongoDBContext
        {
            services.Configure(configuration);
            services.AddSingleton<TContext>();
            services.AddSingleton<IMongoTableFactory, DefaultTableFactory>();
            services.AddSingleton<ISubDatabaseMongoConfig, DefaultSubDatabaseMongoConfig>();
            return services;
        }
    }
}
